package com.starleague.battletech.hexagonal.jpa.appengine;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import com.starleague.battletech.hexagonal.IBattletechHex;
import com.starleague.hexagonal.IHexCoordinate;
import com.starleague.hexagonal.flat.jpa.appengine.AbstractFlatHexGae;

@Entity(name = "BATTLETECH_HEX")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class BattletechHexGae
        extends AbstractFlatHexGae
        implements IBattletechHex
{
    // Remember, AppEngine doesn't support FetchType.EAGER / Joins
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private BattletechHexGridGae hexGrid;

    @Basic(optional = false)
    @Column(nullable = false)
    private int elevation;

    @OneToMany(mappedBy = "hex", cascade = CascadeType.ALL)
    private List<BattletechHexTerrainGae> hexTerrainList = new ArrayList<>();

    BattletechHexGae(BattletechHexGridGae hexGrid,
                     IHexCoordinate hexCoordinate,
                     int elevation)
    {
        super(hexCoordinate);
        this.hexGrid = hexGrid;
        this.elevation = elevation;
    }

    protected BattletechHexGae()
    {
        //
    }

    @Override
    public BattletechHexGridGae getHexGrid()
    {
        return this.hexGrid;
    }

    @Override
    public int getElevation()
    {
        return this.elevation;
    }

    @Override
    public List<BattletechHexTerrainGae> getHexTerrainList()
    {
        return this.hexTerrainList;
    }

    @Override
    public Map<String, Object> infoProperties()
    {
        Map<String, Object> infoPropertyMap = super.infoProperties();
        infoPropertyMap.put("elevation", this.elevation);
        infoPropertyMap.put("terrain", this.hexTerrainList);
        return infoPropertyMap;
    }
}
